<template>
  <div class="app-container calendar-list-container">
    <el-button class="filter-item" type="primary" @click="cancel">返回</el-button>
    <div class="w-body">
      <el-form :model="entity" ref="entity" label-width="80px" size="small">
        <el-row>
          <el-col :span="6">
            <el-form-item label="加工单号" prop="businessCode">
              <el-input v-model="entity.businessCode" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户名称" prop="customerName">
              <el-input v-model="entity.customerName" :disabled="true">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="仓库名称" prop="warehouseName">
              <el-input v-model="entity.warehouseName" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="创建人:" prop="createUserName">
              <span>{{entity.createUserName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="创建时间:" prop="createTime">
              <span>{{entity.createTime}}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="w-table">
              <grid gridTitle="物品信息" :columns="columns" :loading="false" ref="mainGrid" height="400" :pagination="false" :permissions="permissions" :multi="true">
              </grid>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from '@/router/axios'
import { Message, MessageBox } from 'element-ui'
import url from '@/const/apiURL'
import GridDialog from '@/components/GridDialog'
import grid from '@/components/Grid'
import { mapGetters } from 'vuex'
import { queryField } from '@/const/query'

export default {
  components: { GridDialog, grid },
  data () {
    return {
      modelQueryList: queryField().modelName,
      customerName: '',
      warehouseName: '',
      entity: {
        businessCode: '',
        goods: []
      },
      goodsQueryEntity: {},
      columns: [
        { label: this.global.modelName, width: 100, prop: 'goodsName', align: 'left' },
        { label: this.global.modelProp, width: 80, prop: 'modelProp', align: 'left' },
        { label: '物料名称', width: 200, prop: 'materialName', align: 'left' },
        { label: '物料类型', width: 80, prop: 'materialTypeName', align: 'center' },
        { label: '单位', width: 80, prop: 'unit', align: 'center' },
        { label: '序列号', width: 160, prop: 'serialNumber', align: 'center' },
        { label: '批次号', width: 160, prop: 'batchNo', align: 'center' },
        { label: '数量', width: 120, prop: 'quantity', align: 'center' }
      ]
    }
  },
  created () {
    const params = this.$route.query
    this.entity.businessCode = params.businessCode
    this.entity.backCode = params.backCode
    this.init()
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    init () {
      this.initBusiness()
    },
    cancel () {
      this.$router.push({ path: '/prod/business/back', query: { businessCode: this.entity.businessCode } })
    },

    initBusiness () {
      this.businessUrl(this.entity.backCode).then(data => {
        if (data) {
          this.entity = data
          data.goods.forEach(row => {
            this.$refs['mainGrid'].addRow(row)
          })
        }
      })
    },
    businessUrl (backCode) {
      return request({
        url: url.BUSINESS_BACK_VIEW_URL,
        method: 'post',
        params: { backCode: backCode },
        data: { key: 'key' }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.w-body {
  padding-top: 8px;
}
.w-table {
  border: 1px solid #ebeef5;
}
.w-table-title {
  border: 1px solid #ebeef5;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-all;
  line-height: 23px;
  display: inline-block;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  position: relative;
  vertical-align: middle;
  width: 100%;
  font-size: 14px;
  color: gray;
}
</style>
